//
//  IndicatorView.m
//  yunqiphone
//
//  Created by Irewest on 14-8-8.
//  Copyright (c) 2014年 ci123.com. All rights reserved.
//

#import "IndicatorView.h"
#import "OLImageView.h"
#import "OLImage.h"

@implementation IndicatorView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        self.backgroundColor= [UIColor clearColor];
        float marginTop = (frame.size.height - 205) / 2;
        if (!IS_4_INCH) {
            marginTop -= 0;
        }
        
        if (appNetworkStatus != NotReachable) {
            OLImageView *loadingImageView = [OLImageView new];
            [loadingImageView setBackgroundColor:[UIColor clearColor]];
            [loadingImageView setFrame:CGRectMake((frame.size.width - 205) / 2, marginTop, 205, 205)];
            NSString *filePath = [[NSBundle mainBundle] pathForResource:@"base_loading" ofType:@"gif"];
            NSData *gifData = [NSData dataWithContentsOfFile:filePath];
            loadingImageView.image = [OLImage imageWithData:gifData];
            [self addSubview:loadingImageView];
        }else {
            UIImageView *noNetImageView = [[UIImageView alloc]initWithFrame:CGRectMake((frame.size.width - 205) / 2, marginTop, 205, 205)];
            [noNetImageView setImage:[UIImage imageNamed:@"base_nonet"]];
            [noNetImageView setBackgroundColor:[UIColor clearColor]];
            UITapGestureRecognizer *tapReload = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(refreshData:)];
            [noNetImageView addGestureRecognizer:tapReload];
            [noNetImageView setUserInteractionEnabled:YES];
            [self addSubview:noNetImageView];
        }
    }
    
    return self;
}

- (void)refreshData:(UITapGestureRecognizer *)tap
{
    if ([_indicatorDelegate respondsToSelector:@selector(indicatorRefreshData)]) {
        [_indicatorDelegate indicatorRefreshData];
    }
}

@end
